package cn.flying.base.common.vo;

import java.io.Serializable;

import cn.flying.base.common.enums.BaseEnumInfo;
import cn.flying.base.common.enums.RtCodeEnum;

/**
 * @description: 公共的返回对象
 * @author: lvyong
 * @date: 2022年03月31日 20:47
 * @version: 1.0
 */
public class Rt<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;
    private String msg;
    private T data;

    public Rt() {}

    public Rt(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Rt(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Rt success() {
        return new Rt(RtCodeEnum.R_SUCCESS.getCode(), RtCodeEnum.R_SUCCESS.getMessage());
    }

    public static Rt success(Object data) {
        return new Rt(RtCodeEnum.R_SUCCESS.getCode(), RtCodeEnum.R_SUCCESS.getMessage(), data);
    }

    public static Rt success(String message) {
        return new Rt(RtCodeEnum.R_SUCCESS.getCode(), message);
    }

    public static Rt success(String message, Object data) {
        return new Rt(RtCodeEnum.R_SUCCESS.getCode(), message, data);
    }

    public static Rt error() {
        return new Rt(RtCodeEnum.R_ERROR.getCode(), RtCodeEnum.R_ERROR.getMessage());
    }

    public static Rt error(BaseEnumInfo enumInfo) {
        return new Rt(enumInfo.getCode(), enumInfo.getMessage());
    }

    public static Rt error(String message) {
        return new Rt(RtCodeEnum.R_ERROR.getCode(), message);
    }

    public static Rt error(String code, String message) {
        return new Rt(code, message);
    }

    public static Rt result(BaseEnumInfo enumInfo) {
        return new Rt(enumInfo.getCode(), enumInfo.getMessage());
    }

    public static Rt result(BaseEnumInfo enumInfo, Object data) {
        return new Rt(enumInfo.getCode(), enumInfo.getMessage(), data);
    }

    public static Rt result(String code, String message, Object data) {
        return new Rt(code, message, data);
    }

}
